<?php
                            //display quote 
                            
                            
                            $countQuote = count($quoteList);
                            
                            $table=new CI_Table();
                            $tmpl = array ( 
                                'table_open'  => '<table border="0" cellpadding="2" cellspacing="1" class="" width="500">' ,
                                'row_start'=>'<tr style="vertical-align: top;">'
                                );
                            $table->set_template($tmpl);
                            $table->set_heading(array(
                                'Date','Reference','Number','Status','Amount'
                            ));
                            echo "<h2>Quote</h2>";
                            if ($countQuote > 0) {
                                for ($i = 0; $i < $countQuote; $i++) {
                                    
                                    $item = $quoteList[$i];
                                    /* @var $item Invoice */
                                    $paymentList=$item->getPaymentList();
                                    $paymentStr='';
                                    if(count($paymentList)>0){
                                        foreach($paymentList as $payment){
                                            /* @var $payment RecLed */
                                            $paymentStr.=$payment->entryid.'<br/>';
                                        }
                                    }
                                    $data=array(
                                        $item->invoicedate,
                                        NULL,
                                        "<a href='index.php?r=invoices/update&invoice=$item->invoice'>$item->invoice</a>",
                                        $item->getQuoteStatusText(),
                                        number_format($item->amountcharge,2),
                                        $paymentStr
                                    );
                                    $table->add_row($data);
                                    
                                }
                                echo $table->generate();
                            }else {
                                echo "No quote have been created with this job number.";
                            }
                            
                            ?>
                            
                    <h2>Sales Order</h2>
                    <?php 
                    
                    $soCount=count($salesOrderList);
                   
                    $table->set_heading(array(
                        'Date','Reference','Number','Status','Amount'
                    ));
                    if($soCount>0){
                        foreach($salesOrderList as $item){
                            $data=array(
                                $item->invoicedate,
                                $item->quoteorg,
                                "<a href='index.php?r=invoices/update&invoice=$item->invoice'>$item->invoice</a>",
                                JobsStatus::getText($item->salesorderstatus),
                                number_format($item->amountcharge,2),
                            );
                            $table->add_row($data);
                        }
                        echo $table->generate();
                    }else{
                        echo 'No sales orders have been created with this job number.';
                    }
                    ?>
                    <br/>
                    <h2>Invoice</h2>
                    <?php 
                  
                    $invCount=count($invList);
                    $table->set_template(array(
                        'table_open'  => '<table border="0" cellpadding="2" cellspacing="1" class="" width="635">' ,
                        'row_start'=>'<tr style="vertical-align: top;">'
                    ));
                    $table->set_heading(array(
                        'Date','Reference','Number','Status','Amount','Payments'
                    ));
                    if($invCount>0){
                        
                        
                        foreach($invList as $item){
                            $paymentList=$item->getPaymentList();
                            $paymentStr='';
                            if(count($paymentList)>0){
                                
                                
                                foreach($paymentList as $payment){
                                    /* @var $payment RecLed */
                                    
                                    //generate the table
                                    $payTable=new CI_Table;
                                    $payTable->set_template(array(
                                        'table_open'=>'<table border="0" cellpadding="0" cellspacing="0" class="" width="200">',
                                        
                                    ));
                                    $payTable->set_heading(array(
                                        'Amount','Entry Date','Type'
                                    ));
                                    $payTable->add_row(array($payment->amount,$payment->entrydate,$payment->type));
                                    //register the tooltip script
                                    Yii::app()->clientScript->registerScript("payment-$payment->entryid","
                                        $('.payment-$payment->entryid').hide();
                                        $('#payment-$payment->entryid').qtip({
                                            content:$('.payment-$payment->entryid')
                                            });
                                        ");
                                    $paymentStr.=<<<HERE
                                        <a href="#" id='payment-$payment->entryid'>$payment->entryid - $payment->amount</a>
                                        <div  class='payment-$payment->entryid'>
                                            {$payTable->generate()}
                                        </div><br/>
                                        
HERE;
                                            
                                }
                            }
                            $data=array(
                                $item->invoicedate,
                                $item->quoteorg,
                                "<a href='index.php?r=invoices/update&invoice=$item->invoice'>$item->invoice</a>",
                                $item->getQuoteStatusText(),
                                number_format($item->amountcharge,2),
                                $paymentStr
                            );
                            $table->add_row($data);
                        }
                        echo $table->generate();
                    }else{
                        echo 'No invoice have been created with this job number.';
                    }
                    ?>